﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WorkStation.Frameworks.EasyBus.Pipeline;
using WorkStation.Frameworks.EasyBus.MessageQueue;
using WorkStation.Frameworks.EasyBus.Pipeline.Handles;

namespace WorkStation.Frameworks.EasyBus
{
    /// <summary>
    /// 消息监听器
    /// </summary>
    public interface IMessageListener
    {
        event Action<BusActionContext, FailHandleResult> OnProcessFail;
        event Action<BusActionContext, SuccessHandleResult> OnProcessSuccess;
        event Action<BusActionContext> OnProcessBefore;
        event Action<BusActionContext, IEnumerable<HandleResult>> OnProcessAfter;

        event Action<Exception> OnListenException;

        /// <summary>
        /// 所监听的终结点
        /// </summary>
        IEndpoint Endpoint { get; set; }

        /// <summary>
        /// 监听器名称
        /// </summary>
        string Name { get; set; }

        /// <summary>
        /// 监听线程数
        /// </summary>
        int ProcessThreadCount { get; set; }

        /// <summary>
        /// 处理消息管道
        /// </summary>
        IPipeline ReceiveMessagePipeline { get; set; }

        /// <summary>
        /// 总线对象
        /// </summary>
        IBus Bus { get; set; }

        /// <summary>
        /// 是否启用
        /// </summary>
        bool Enabled { get; set; }

        /// <summary>
        /// 订阅处理消息处理器
        /// </summary>
        /// <param name="msgType">消息类型</param>
        /// <param name="handle">处理器对象</param>
        /// <returns></returns>
        IMessageListener Subscribe(string msgType, IHandle handle);

        /// <summary>
        /// 开始监听
        /// </summary>
        void BeginListen();

        /// <summary>
        /// 停止监听
        /// </summary>
        void StopListen();
    }
}
